<template>
<div>
    <!-- Form -->
    <el-button type="NewlyBuild" @click="dialogFormVisible = true" icon="el-icon-plus" v-if="_SHOWBTN(showBetCode)">新建</el-button>
    <el-dialog title="新建清风论坛" :visible.sync="dialogFormVisible" width="530px">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <!--输入框-->
            <el-form-item label=" 图片名称：" prop="name">
                <el-input v-model="ruleForm.name" placeholder="请输入图片名称"></el-input>
            </el-form-item>
            <!--下拉框-->
            <el-form-item label=" 图片位置：" prop="space">
                <el-select v-model="ruleForm.space" placeholder="请输入">
                    <el-option label="清风论坛图" value="FORUM_PIC"></el-option>
                    <el-option label="亦廉课堂图" value="YL_CLASS"></el-option>
                    <el-option label="他山之石图" value="LEARN_OTHER"></el-option>
                    <el-option label="警示教育图" value="ARM_YOUSELF"></el-option>
                </el-select>
            </el-form-item>
            <!--本地图片选择-->
            <div class="pic-box">
                <h1 class="h1-1">选择图片：</h1>
                <Upload :ruleForm.sync="ruleForm" ref="upload"></Upload>
            </div>
            <!--图片提示文字及边框-->
            <div class="flex-box">
                <div class="pic-Tips">
                    <h1>1.请上传PNG、JPG或者JPEG图片，大小不超过10MB;</h1>
                    <h1>2.清风论坛图尺寸约为1920*455；亦廉课堂图/他山之石图/警示教育图尺寸约为348*180px；</h1>
                </div>
            </div>

            <!--下拉框
        <el-form-item label=" 排序：" prop="region">
          <el-select v-model="ruleForm.sort" placeholder="1">
            <el-option label="1" value="1"></el-option>
            <el-option label="2" value="2"></el-option>
            <el-option label="3" value="3"></el-option>
            <el-option label="4" value="4"></el-option>
            <el-option label="5" value="5"></el-option>
          </el-select>
        </el-form-item>-->
            <!--下拉框-->
            <el-form-item label=" 状态：" prop="used">
                <el-select v-model="ruleForm.used" placeholder="停用">
                    <el-option label="启用" value="1"></el-option>
                    <el-option label="停用" value="0"></el-option>
                </el-select>
            </el-form-item>
        </el-form>

        <!--文本框-->
        <div class="text-box">
            <h1 class="text-title">描述：</h1>
            <el-input type="textarea" placeholder="这里是图片描述" v-model="ruleForm.textarea200" maxlength="200" show-word-limit></el-input>
        </div>

        <!--结束-->
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="BuildNew('ruleForm')">确 定</el-button>
        </div>
    </el-dialog>
</div>
</template>

<script>
import Upload from "@/components/Upload/Upload.vue";
export default {
    components: {
        Upload,
    },
    data() {
        return {
            dialogFormVisible: false,
            ruleForm: {
                name: "",
                space: "",
                used: "",
                //文本框
                textarea200: "",
                picUrl: "",
            },
            rules: {
                name: [{
                        required: true,
                        message: "请输入图片名称",
                        trigger: "blur"
                    },
                    {
                        message: "长度在 1 到 20 个字符",
                        trigger: "blur"
                    },
                ],
                space: [{
                    required: true,
                    message: "请选择图片位置",
                    trigger: "blur"
                }, ],
                used: [{
                    required: true,
                    trigger: "blur",
                    message: "请选择状态",
                }, ],
            },
        };
    },
    props: ["getForumList", "showBetCode"],
    methods: {
        //新建按钮点击事件确认
        BuildNew(formName) {
            //   this.dialogFormVisible = false;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.Api.getFroumAdd({
                        picCode: this.ruleForm.space,
                        picDesc: this.ruleForm.textarea200,
                        picName: this.ruleForm.name,
                        picUrl: this.ruleForm.picUrl,
                        used: this.ruleForm.used,
                    }).then((res) => {
                        if (res.code === "0") {
                            this.dialogFormVisible = false;
                            this.getForumList();
                            this.ruleForm = {
                                name: "",
                                space: "",
                                used: "",
                                //文本框
                                textarea200: "",
                                picUrl: "",
                            }
                            this.$refs.upload.$refs.uploadFile.clearFiles()
                            // console.log(res,11111)
                            // alert("submit!");
                        }
                    });
                } else {
                    // console.log("error submit!!");
                    return false;
                }
            });
        },
    },
};
</script>

<style lang="less" scoped>
/deep/.el-button--NewlyBuild {
    width: 80px;
    height: 36px;
    background: rgba(61, 127, 255, 1);
    border-radius: 3px;
    padding: 0;
    color: white;
    margin-right: 10px !important;
}

/deep/.el-dialog__wrapper {
    z-index: 2091 !important;

    .el-dialog {
        .el-dialog__header {
            background: rgba(230, 233, 237, 1);
            border-radius: 8px 8px 0px 0px;
            border: 1px solid rgba(230, 233, 237, 1);
            padding: 11px 20px 11px 24px;

            .el-dialog__title {
                font-size: 18px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: rgba(51, 51, 51, 1);
                line-height: 24px;
            }

            .el-dialog__headerbtn {
                top: 15px;
            }
        }

        .el-dialog__body {
            padding: 30px 43px 0 42px;

            .el-form {
                .el-form-item {
                    margin: 0 0 16px 0;

                    .el-form-item__label {
                        width: 85px !important;
                        font-size: 14px;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #333333;
                        padding: 0;
                    }

                    .el-form-item__content {
                        margin-left: 85px !important;

                        .el-input__inner {
                            width: 260px;
                            height: 36px;
                            background: rgba(255, 255, 255, 1);
                            border-radius: 4px;
                            border: 1px solid rgba(221, 221, 221, 1);
                            padding-left: 12px;
                        }
                    }
                }

                .pic-box {
                    display: flex;
                    padding-bottom: 10px;

                    .h1-1 {
                        width: 85px;
                        height: 22px;
                        font-size: 14px;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #333333;
                        text-align: right;
                    }

                    .h1-1::before {
                        content: "* ";
                        color: #ff0000;
                    }

                    .upload-box {
                        .el-dialog__wrapper {
                            .el-dialog {}
                        }
                    }
                }

                .flex-box {
                    display: flex;
                    justify-content: flex-end;

                    .pic-Tips {
                        width: 360px;
                        padding-top: 6px;
                        padding-bottom: 15px;
                        border-top: 1px solid #dddddd;

                        h1 {
                            font-size: 12px;
                            font-family: PingFangSC-Regular, PingFang SC;
                            font-weight: 400;
                            color: rgba(153, 153, 153, 1);
                            line-height: 22px;
                        }
                    }
                }
            }

            .text-box {
                display: flex;

                .text-title {
                    width: 105px;
                    height: 22px;
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    text-align: right;
                }

                .text-title::before {
                    // content: "* ";
                    color: #ff0000;
                }

                .el-textarea__inner {
                    min-height: 100px !important;
                    padding-left: 10px;
                }
            }
        }

        .el-dialog__footer {
            padding: 30px 30px 26px;

            .dialog-footer {
                .el-button--default {
                    width: 70px;
                    height: 36px;
                    background: rgba(255, 255, 255, 1);
                    border-radius: 3px;
                    border: 1px solid rgba(215, 219, 224, 1);
                    padding: 0;
                    color: rgba(51, 51, 51, 1);
                }

                .el-button--primary {
                    width: 70px;
                    height: 36px;
                    background: rgba(61, 127, 255, 1);
                    border-radius: 3px;
                    padding: 0;
                    color: rgba(255, 255, 255, 1);
                }
            }
        }
    }
}

/**图片上传大小修改88px */
/deep/.el-upload--picture-card {
    width: 88px;
    height: 88px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/deep/.el-upload-list__item {
    width: 88px;
    height: 88px;
    margin-right: 0px;
}

/deep/.el-icon-zoom-in {
    font-size: 19px;
}

/deep/.el-icon-download {
    font-size: 19px;
}

/deep/.el-icon-delete {
    font-size: 19px;
}

.upload-box {
    width: 88px;
    height: 88px;
    overflow: hidden;

    ul {
        li {
            div {
                >span {
                    display: flex;
                }
            }
        }
    }
}
</style>
